package com.example.onion.hxchat.activity;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.example.onion.hxchat.adapter.MyMsgAdapter;
import com.example.databean.Msg;
import com.example.onion.hxchat.mvvm.InfoViewModel;
import com.example.onion.hxchat.room.entity.Info;
import com.example.onion.hxchat.util.MyLocalDatabaseHelper;
import com.example.onion.hxchat.util.PassWordHelp;
import com.example.superyi.myteam.R;
import com.hyphenate.EMCallBack;
import com.hyphenate.EMMessageListener;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMTextMessageBody;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 需要调用消息活动页面，需要给出聊天对象userId（传递到本页面的key值应该是chatUserId)
 * 和用户名userName（传递到本页面的key值应该是chatUserName）
 * userName = getIntent().getStringExtra("chatUserName");
 * chatToUserId = getIntent().getStringExtra("chatUserId");
 * 含version
 */
public class MsgTestActivity extends AppCompatActivity implements EMMessageListener {

    private void initData() {
        //获得前一个页面传递过来的用户名
        userName = getIntent().getStringExtra("chatUserName");
        chatToUserId = getIntent().getStringExtra("chatUserId");
        accountId = PassWordHelp.readPassword(MsgTestActivity.this)[0];
        Log.e("MsgActivity", "MsgActivity initData");
        //MyDatabaseHelper databaseHelper = new MyDatabaseHelper(this,"ChatLog1.db",null,1);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        Cursor cursor = db.rawQuery("select * from chatDb where (userId = ? and toUserId = ? )or (userId =? and toUserId=?)",
                new String[]{chatToUserId, accountId, accountId, chatToUserId});
        //     聊天对象发给我的             我发送聊天对象的   都是当前界面应该初始化的本地数据
        if (cursor.moveToFirst()) {
            do {
                String UserId = cursor.getString(cursor.getColumnIndex("userId"));
                String toUserId = cursor.getString(cursor.getColumnIndex("toUserId"));
                String content = cursor.getString(cursor.getColumnIndex("content"));
                String time = cursor.getString(cursor.getColumnIndex("time"));
                int type = cursor.getInt(cursor.getColumnIndex("type"));
                int id = cursor.getInt(cursor.getColumnIndex("id"));
                Msg msg = new Msg(content, type, UserId, toUserId, time);
//                Log.e("query UserId", UserId);
//                Log.e("query toUserId", toUserId);
//                Log.e("query content", content);
//                Log.e("query time", time);
//                Log.e("query type", String.valueOf(type));
//                Log.e("query id", String.valueOf(id));
                msgList.add(msg);
            } while (cursor.moveToNext());
        }
    }

    private int version = 4;

    private MyLocalDatabaseHelper dbHelper;

    private List<Msg> msgList = new ArrayList<Msg>();

    private EditText inputText;

    private Button send;

    private RecyclerView msgRecyclerView;

    private MyMsgAdapter adapter;

    private Toolbar toolbar;

    private TextView userNameTv;//显示用户名称的容器

    //chatOb...是在msg_item页面的部件，当前页面没有加载msg_item.xml，得不到部件，出现错误
//    private TextView chatObjectUserName;///显示当前页面聊天用户的名称的部件
//    private TextView chatOwnUserName;////显示当前页面本人用户名的部件

    private String userName;//当前页面上方显示的用昵称

    private String chatToUserId;//当前页面聊天对象的用户id

    private String accountId;//当前登录用户的id

    private SwipeRefreshLayout swipeRefreshLayout;


    private LinearLayout layout_edit;//解决软键盘遮挡聊天信息找到的解决方案用到的

    private DataInitListener mDataInitListener;//通知显示内容的fragment刷新数据


//    private final String CHAT_CONTENT_FRAGMENT = "catContentFragment";
////    private FragmentManager fragmentManager;

    @SuppressLint("HandlerLeak")
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    msgRecyclerView.scrollToPosition(msgList.size() - 1);
                    break;
            }
        }

    };


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)//不知道咋出来的
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_msg_test);
        dbHelper = new MyLocalDatabaseHelper(this, "local.db", null, version);
        infoViewModel = new ViewModelProvider(this).get(InfoViewModel.class);
        initData(); // 初始化消息数据
        initView();
    }

    /**
     * 初始化部件
     */
    @SuppressLint("ClickableViewAccessibility")
    private void initView() {
        inputText = findViewById(R.id.chat_input_text);
        send = findViewById(R.id.chat_send_btn);
        Log.e("userName == null?", String.valueOf(userName == null));
        userNameTv = findViewById(R.id.chat_toolbar_user_name);
        layout_edit = findViewById(R.id.layout_edit);
        userNameTv.setText(userName);//设置得到的名称
        swipeRefreshLayout = findViewById(R.id.chat_swiperefreshlayout);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                //此处给出聊天界面刷新的逻辑代码
                Toast.makeText(MsgTestActivity.this, "刷新成功", Toast.LENGTH_SHORT).show();
                swipeRefreshLayout.setRefreshing(false);

            }
        });
        msgRecyclerView = findViewById(R.id.msg_recycler_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        msgRecyclerView.setLayoutManager(layoutManager);
//        adapter.notifyItemInserted(msgList.size() - 1); // 当有新消息时，刷新ListView中的显示
        msgRecyclerView.scrollToPosition(msgList.size() - 1); // 将ListView定位到最后一行
        /**                 以下是为了软键盘不遮挡聊天记录找到的代码           **/
        layout_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                inputText.requestFocus();
                showSoftInput(MsgTestActivity.this, inputText);
                handler.sendEmptyMessageDelayed(0, 250);
            }
        });

        msgRecyclerView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                hideSoftInput(MsgTestActivity.this, inputText);
                return false;
            }
        });
        /**                 以上是为了软键盘不遮挡聊天记录找到的代码           **/
        adapter = new MyMsgAdapter(msgList,MsgTestActivity.this);
        msgRecyclerView.setAdapter(adapter);
        toolbar = findViewById(R.id.chat_toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }

        // 发送消息的代码
        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
//                dbHelper1 = new MyInfoDataBaseHelper(MsgTestActivity.this, "info.db", null, 2);
//                SQLiteDatabase db1 = dbHelper1.getWritableDatabase();
                String content = inputText.getText().toString();
                //创建一条文本消息，content为消息文字内容，userId为对方用户或者群聊的id，后文皆是如此
                EMMessage message = EMMessage.createTxtSendMessage(content, chatToUserId);
                //如果是群聊，设置chattype，默认是单聊
                //if (chatType == CHATTYPE_GROUP)
                // message.setChatType(EMMessage.ChatType.GroupChat);
                // mContentView.setText(mContentView.getText()+"\n"+content);
                /** 加入mList  */
                if (!"".equals(content)) {
                    Msg msg = new Msg(content, Msg.TYPE_SENT, accountId, chatToUserId, genCurrentTime());
                    db.execSQL("insert into chatDb(userId,toUserId,content,type,time) values(?,?,?,?,?)"
                            , new String[]{msg.getUserId(), msg.getToUserId(), msg.getContent(), String.valueOf(msg.getType()), msg.getTime()});

                    infoViewModel.insertJustLastInfo(((EMTextMessageBody) message.getBody()).getMessage(), message.getUserName(),accountId);
//                    db.execSQL("update infoItem set lastInfo = ? where userId = ? and ownerUserId=?"
//                            , new String[]{content, chatToUserId, accountId});
                    //新发送的信息会成为外围消息列表显示的最新一条信息
                    msgList.add(msg);
                    adapter.notifyItemInserted(msgList.size() - 1); // 当有新消息时，刷新ListView中的显示
                    //此处可以写保存聊天信息到本地数据库
                    msgRecyclerView.scrollToPosition(msgList.size() - 1); // 将ListView定位到最后一行
                    inputText.setText(""); // 清空输入框中的内容
                }
                message.setMessageStatusCallback(new EMCallBack() {
                    @Override
                    public void onSuccess() {
                        Log.d("application", "消息发送成功");
                    }

                    @Override
                    public void onError(int i, String s) {
                        Log.d("application", "消息发送失败" + s);
                    }

                    @Override
                    public void onProgress(int i, String s) {

                    }
                });
                //发送消息
                EMClient.getInstance().chatManager().sendMessage(message);
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home://系统自带的返回箭头的资源id
                finish();
                break;
        }
        return true;
    }

    public List<Msg> getMsgList() {
        return msgList;
    }


    private static final String FORMATER = "yyyy:MM:dd,HH:mm:ss";

    /**
     * 转化时间                        <br>
     */
    public static String genCurrentTime(Date date) {
        SimpleDateFormat formater = new SimpleDateFormat(FORMATER);
        return formater.format(date);
    }

    /**
     * 生成当前时间                        <br>
     */
    public static String genCurrentTime() {
        SimpleDateFormat formater = new SimpleDateFormat(FORMATER);
        return formater.format(new Date());
    }

    public String getTitles() {
        return "titles";
    }

    /**
     * 判断当前环信格式的消息相对于登录的用户来说，是接收的消息还是发送的消息
     *
     * @param message 一条环信格式的消息数据
     * @param userId  当前登录的用户id
     * @return 相对于登录的用户，是发送的返回true，接收的返回false
     */
    private boolean isHxMessageSend(EMMessage message, String userId) {
        //环信消息的发送人等于当前登录的用户的id，则当前用户是发送该消息的人，返回true
        if (message.getFrom().equals(userId)) {
            return true;
        }
        return false;
    }

    @Override
    protected void onResume() {
        super.onResume();
        //注册消息监听
        EMClient.getInstance().chatManager().addMessageListener(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //取消消息监听
        EMClient.getInstance().chatManager().removeMessageListener(this);
    }


    private String createNotificationChannel(String channelID, String channelNAME, int level) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            NotificationChannel channel = new NotificationChannel(channelID, channelNAME, level);
            manager.createNotificationChannel(channel);
            return channelID;
        } else {
            return null;
        }
    }


    /**
     * 收到消息,环信重载方法，进行接收消息处理
     *
     * @param list 环信消息集合
     */
    @Override
    public void onMessageReceived(List<EMMessage> list) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
//        dbHelper1 = new MyInfoDataBaseHelper(this, "info.db", null, 2);
//        SQLiteDatabase db1 = dbHelper1.getWritableDatabase();
        for (EMMessage message : list) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(MsgTestActivity.this, MainActivityWC.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    PendingIntent pendingIntent = PendingIntent.getActivity(MsgTestActivity.this, 0, intent, 0);
                    String channelId = createNotificationChannel("my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
                    NotificationCompat.Builder notification = new NotificationCompat.Builder(MsgTestActivity.this, channelId)
                            .setContentTitle(message.getFrom())
                            .setContentText("收到一条消息")
                            .setWhen(System.currentTimeMillis())//通知栏显示时间
                            .setContentIntent(pendingIntent)//关联点击通知栏跳转页面
                            .setSmallIcon(R.mipmap.ic_launcher)//通知栏小图标
                            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))//通知栏下拉是图标
                            .setContentIntent(pendingIntent)//关联点击通知栏跳转页面
                            .setPriority(NotificationCompat.PRIORITY_MAX)//设置通知消息优先级
                            .setAutoCancel(true)//设置点击通知栏消息后，通知消息自动消失
                            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) //通知栏提示音、震动、闪灯等都设置为默认
                            .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
                            .setPriority(NotificationCompat.PRIORITY_HIGH)
//                            .setStyle(new NotificationCompat.InboxStyle()
//                                    .addLine(((EMTextMessageBody) message.getBody()).getMessage()))
                            .setAutoCancel(true)
                            .setStyle(new NotificationCompat.BigTextStyle().
                                    bigText(((EMTextMessageBody) message.getBody()).getMessage()));
                    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MsgTestActivity.this);
                    notificationManager.notify(100, notification.build());
                    Msg msg = new Msg(((EMTextMessageBody) message.getBody()).getMessage(), Msg.TYPE_RECEIVED, message.getUserName(), accountId, genCurrentTime());
//                    db.execSQL("insert into chatDb(userId,toUserId,content,type,time) values(?,?,?,?,?)"
//                            , new String[]{msg.getUserId(), msg.getToUserId(), msg.getContent(), String.valueOf(msg.getType()), msg.getTime()});
                    if (!isExistUserIdInfo(message.getUserName())) {
                        //不存在与userId用户的对话框插入
                        Info info = new Info(message.getUserName(),((EMTextMessageBody) message.getBody()).getMessage(),message.getUserName(),accountId);
                        infoViewModel.insertInfo(info);
                        db.execSQL("insert into infoItem(userId,userName,lastInfo,ownerUserId) values(?,?,?,?)"
                                , new String[]{message.getUserName(), message.getUserName(), ((EMTextMessageBody) message.getBody()).getMessage(),accountId});
                    } else {//存在只需修改最新一条消息即可
                        infoViewModel.insertJustLastInfo(((EMTextMessageBody) message.getBody()).getMessage(), message.getUserName(),accountId);
//                        db.execSQL("update infoItem set lastInfo = ? where userId = ? and ownerUserId =?"
//                                , new String[]{((EMTextMessageBody) message.getBody()).getMessage(), message.getUserName(),accountId});
                    }
                    Log.e("MsgActivity消息的用户名", message.getUserName());
                    //getUserName获得当前发送信息的用户在环信后台的用户id
                    if (userName == null) {
                        userName = message.getUserName();
                        userNameTv.setText(userName);
                    }
                    //保证监听到的信息只显示给当前聊天的用户所见（即聊天页面对方发给你的消息才会直接显示，否则会直接后台保存）
                    if (msg.getUserId().equals(chatToUserId)) {
                        msgList.add(msg);
                        adapter.notifyItemInserted(msgList.size() - 1); // 当有新消息时，刷新ListView中的显示
                        msgRecyclerView.scrollToPosition(msgList.size() - 1); // 将ListView定位到最后一行
                    }

                }
            });
        }
        //此处可以写保存聊天信息到本地数据库
        //环信导入消息到数据库（对于消息，环信sdk会自动创建本地数据库)
        EMClient.getInstance().chatManager().importMessages(list);
    }
    private InfoViewModel infoViewModel;
    /**
     * 判断数据库是否存在与userId用户的对话框
     *
     * @param userId id
     * @return 存在true 否则false
     */
    private boolean isExistUserIdInfo(String userId) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        Cursor cursor = db.rawQuery("select userName from infoItem where userId = ?"
                , new String[]{userId});
        if (cursor.moveToFirst()) {//查出来数据表示存在与userId用户的对话框了
            return true;
        }
        return false;
    }

    //唤醒屏幕并解锁
    public void wakeUpAndUnlock(Context context) {
        KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
        //解锁
        kl.disableKeyguard();
        //获取电源管理器对象
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
        @SuppressLint("InvalidWakeLockTag") PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
        //点亮屏幕
        wl.acquire();
        //释放
        wl.release();
    }

//没用到
//    /**
//     * 设置通知栏消息样式
//     * */
//    @SuppressLint("WrongConstant")
//    private void setNotification(NotificationManager manager, Notification.Builder builder,Notification notification, int type) {
//        //点击通知栏消息跳转页
//        Intent intent = new Intent(this, MsgTestActivity.class);
//        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
//        //创建通知消息管理类
//        manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//        builder = new Notification.Builder(this)//创建通知消息实例
//                .setContentTitle("我是标题")
//                .setContentText("我是内容")
//                .setWhen(System.currentTimeMillis())//通知栏显示时间
//                .setSmallIcon(R.mipmap.ic_launcher)//通知栏小图标
//                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))//通知栏下拉是图标
//                .setContentIntent(pendingIntent)//关联点击通知栏跳转页面
//                .setPriority(NotificationCompat.PRIORITY_MAX)//设置通知消息优先级
//                .setAutoCancel(true)//设置点击通知栏消息后，通知消息自动消失
////                .setSound(Uri.fromFile(new File("/system/MP3/music.mp3"))) //通知栏消息提示音
//                .setVibrate(new long[]{0, 1000, 1000, 1000}) //通知栏消息震动
//                .setLights(Color.GREEN, 1000, 2000) //通知栏消息闪灯(亮一秒间隔两秒再亮)
//                .setDefaults(NotificationCompat.DEFAULT_ALL); //通知栏提示音、震动、闪灯等都设置为默认
//
//        if (type == 1) {
//            //短文本
//            notification = builder.build();
//            //Constant.TYPE1为通知栏消息标识符，每个id都是不同的
//            manager.notify(Constant.TYPE1, notification);
//        } else if (type == 2) {
//            //长文本
//            notification = builder.setStyle(new NotificationCompat.BigTextStyle().
//                    bigText("我是长文字内容:　今年双十一结束后，一如既往又出现了一波冲动剁手党被理智唤醒的退货潮。不过，一位来自福建厦门的网友在这其中贡献了堪称历史里程碑式的高光时刻。别人退衣服退鞋子，而他要退的是一只蓝孔雀、一只宠物小香猪、还有一斤娃娃鱼……"))
//                    .build();
//            manager.notify(Constant.TYPE2, notification);
//        } else {
//            //带图片
//            notification = builder.setStyle(new NotificationCompat.BigPictureStyle().
//                    bigPicture(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)))
//                    .build();
//            manager.notify(Constant.TYPE3, notification);
//        }
//    }


    @Override
    public void onCmdMessageReceived(List<EMMessage> list) {

    }

    @Override
    public void onMessageRead(List<EMMessage> list) {

    }

    @Override
    public void onMessageDelivered(List<EMMessage> list) {

    }

    @Override
    public void onMessageRecalled(List<EMMessage> list) {

    }

    @Override
    public void onMessageChanged(EMMessage emMessage, Object o) {

    }

    public interface DataInitListener {//适配器内创建一个回调接口，获取每一行recyclerview的相关数据

        void initData(Msg msg);//将本页面的获得的infoBean数据通过接口回调给调用方
    }

    public void setDataInitListener(DataInitListener dataInitListener) {
        this.mDataInitListener = dataInitListener;
    }

    //以下两个方法是找到的解决软键盘遮挡聊天信息的方法
    public static void showSoftInput(Context context, View view) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
    }

    public static void hideSoftInput(Context context, View view) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

    }

//    @Override
//    public void onBackPressed() {
//        //方式一：将此任务转向后台
//        moveTaskToBack(false);
//
//        //方式二：返回手机的主屏幕
//    /*Intent intent = new Intent(Intent.ACTION_MAIN);
//    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//    intent.addCategory(Intent.CATEGORY_HOME);
//    startActivity(intent);*/
//    }
    //后台运行而不退出程序

//    @Override
//    public void onBackPressed() {//重写的Activity返回
//
//        Intent intent = new Intent();
//        intent.setAction("android.intent.action.MAIN");
//        intent.addCategory("android.intent.category.HOME");
//        startActivity(intent);
//
//    }
//    /**
//     * 设置返回键不关闭应用,回到桌面
//     *
//     * @param keyCode
//     * @param event
//     * @return
//     */
//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//
//        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
//            //启动一个意图,回到桌面
//            Intent backHome = new Intent(Intent.ACTION_MAIN);
//            backHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            backHome.addCategory(Intent.CATEGORY_HOME);
//            startActivity(backHome);
//            return true;
//        }
//        return super.onKeyDown(keyCode, event);
//    }


}
